import config from 'config'
import httpFetch from 'share/httpFetch'
import errorMessage from "share/errorMessage";

export default {
  getBillingList(params){
    return httpFetch.get(`${config.baseUrl}/api/receipted/invoices/tenant`, params)
  },
  //获取供应商账号
  getCompanyAccount(vendor,companyOid){
    return httpFetch.get(`${config.baseUrl}/api/receipted/invoices/vendor/company/account/query/${vendor}`, { companyOid })
  },
  //查询详情页面
  getCompanyReceiptedInvoicesDetail(params){
    return httpFetch.get(`${config.baseUrl}/api/receipted/invoices/detail/query`,params)
  },
  //开票详情查询费用列表,分页
  getCompanyReceiptedInvoicesByPage(params){
    return httpFetch.get(`${config.baseUrl}/api/receipted/invoices/order/detail/query`,params)
  },

  //导出订单明细
  exportInvoiceDetail(receiptedInvoiceOID){
    return httpFetch.get(`${config.baseUrl}/api/receipted/invoices/export/detail/${receiptedInvoiceOID}`,{},{},{responseType: 'arraybuffer'})
  },

  //重新开票
  reApplyForReceiptedInvoice(receiptedInvoiceOID){
    return httpFetch.put(`${config.baseUrl}/api/receipted/invoices/reOpen/ticket/${receiptedInvoiceOID}`)
  },

  //确认收票
  receiptedInvoice(receiptedInvoiceOID){
    return httpFetch.post(`${config.baseUrl}/api/receipted/invoices/check/${receiptedInvoiceOID}`)
  },

  //获取全部的开票规则
  getAllReceiptRules(vendorType,page){
    return httpFetch.get(`${config.baseUrl}/api/key/invoices/all/query/${vendorType}`,{ page })
  },

  //查询一键开票规则详情
  getSmartRuleDetail(keyInvoiceOID){
    return httpFetch.get(`${config.baseUrl}/api/key/invoices/${keyInvoiceOID}`)
  },

  //批量开票信息
  getBatchOpenTicketInfo(params){
    return httpFetch.post(`${config.baseUrl}/api/receipted/invoices/key/invoices/count/v2`,params)
  },

  // 一键开票
  openTicket(params){
    return httpFetch.post(`/api/key/invoice/quickly/invoice`, params)
  },

  //批量开票
  batchOpenTicket(params){
    return httpFetch.post(`${config.baseUrl}/api/receipted/invoices/key/invoices/v2`,params)
  },

  //删除开票条件
  deleteTicketRules(id){
    return httpFetch.delete(`${config.baseUrl}/api/key/invoices/${id}`)
  },

  //获取抬头options
  getInvoiceTitle(vendorType,params){
    return httpFetch.get(`${config.baseUrl}/api/receipted/invoices/qualifications/query/with/authority/${vendorType}`,params)
  },

  //获取默认地址
  getDefaultAddress(){
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/billing/contacts/default`).then(res => {
        resolve(res);
      }).catch(err => {
        errorMessage(err.response);
        reject(err.response);
      })
    })
  },

  //获取收货地址
  getAddresses(companyOID,params){
    return httpFetch.get(`${config.baseUrl}/api/billing/contacts/company/${companyOID}?`,params)
  },

  //获取所有的省份
  getAllProvinces(){
    return httpFetch.get(`${config.baseUrl}/api/areas/provinces`)
  },

  //获取城市
  getCities(code){
    return httpFetch.get(`${config.baseUrl}/api/areas/cities/${code}`)
  },

  //获取所有区域
  getAreas(params){
    return httpFetch.get(`${config.baseUrl}/api/areas/areas/by/name?`,params)
  },

  //修改收货地址
  editAddress(flag,params){
    let method = flag === 'new' ? 'post' : 'put'
    return httpFetch[method](`${config.baseUrl}/api/billing/contacts`,params)
  },

  //批量获取法人实体
  getBatchCorporationEntityList(params){
    return httpFetch.post(`${config.baseUrl}/api/company/receipted/invoice/oids`,params)
  },

  //批量获取部门
  getBatchDepartmentList(params){
    return httpFetch.post(`${config.baseUrl}/api/departments/oids`,params)
  },

  //批量获取成本中心
  getBatchCostCenterList(params){
    return httpFetch.post(`${config.baseUrl}/api/cost/center/items/oids`,params)
  },

  //查询联系地址详情
  getBillContactDetail(billingContactOID){
    return httpFetch.get(`${config.baseUrl}/api/billing/contacts/${billingContactOID}`)
  },

  //查询开票-获取开票费用信息
  getInvoiceMessage(vendorType,params){
    return httpFetch.post(`${config.baseUrl}/api/receipted/invoices/count/${vendorType}`,params)
  },

  //查询开票-申请开票
  applyForReceiptedInvoice(vendorType,params){
    return httpFetch.post(`${config.baseUrl}/api/receipted/invoices/apply/open/ticket/${vendorType}`,params)
  },
 //查询开票邮箱
  getEmail(){
    return httpFetch.get(`${config.baseUrl}/api/custom/enumerations/滴滴开票邮箱地址/items/v3`)
  },
  
  //新建常用开票条件
  addSmartRule(params){
    return httpFetch.post(`${config.baseUrl}/api/key/invoices/submit`,params)
  },

  //修改常用开票条件
  updateSmartRule(params){
    return httpFetch.put(`${config.baseUrl}/api/key/invoices`,params)
  },

  //得到商务卡的类型
  getCommercialType(companyOID){
    return httpFetch.get(`${config.baseUrl}/api/tenant/bankcard/status/dto?companyOid=${companyOID}`)
  },
  //获取供应商支持的发票类型
  getVendorInvoiceType(vendor, taxpayerNumber){
    let temp = {};
    taxpayerNumber && (temp.taxpayerNumber = taxpayerNumber);
    return httpFetch.get(`${config.baseUrl}/api/invoice/type/${vendor}`,temp)
  },
  //根据id查看商务卡详情
  getCommercialByCode(params){
    return httpFetch.post(`${config.baseUrl}/api/bankcard/type/by/codes`,params)
  },

  //获取开票详情
  getViewDetail(vendorType,params){
    return httpFetch.post(`${config.baseUrl}/api/receipted/invoices/count/detail/${vendorType}`,{...params, page: params.page+1})
  },

  //获取详情费用数据
  getDetailDate(vendorType,params){
    return httpFetch.post(`${config.baseUrl}/api/receipted/invoices/count/expense/report/detail/${vendorType}`,params)
  },

  //获取发票状态查询的下拉列表
  getInvoiceTable(params){
    return httpFetch.post(`${config.baseUrl}/api/didi/invoices/query`,params);
  },

  // 获取默认开票
  getDefaultTicket(vendor) {
    return httpFetch.get(`/api/legalEntity/invoiceType/query/all/legalEntities/${vendor}`);
  },

  saveDefaultTicket(vendor, params) {
    return httpFetch.post(`/api/legalEntity/invoiceType/save/${vendor}`, params);
  }

}
